#include<iostream>
#include<mutex>
#include<thread>
#include<condition_variable>
using namespace std;

void two_thread_print()
{
	mutex mtx;
	condition_variable c;
	int n = 100;
	bool flag = true;

	thread t1([&]()
		{
			int i = 1;
			while (i <= 100)
			{
				unique_lock<mutex> lock(mtx);
				c.wait(lock, [&]()->bool {return flag; });
				cout << i << endl;
				flag = false;
				i += 2;
				c.notify_one();
			}
		});

	thread t2([&]()
		{
			int j = 2;
			while (j <= n)
			{
				unique_lock<mutex> lock(mtx);
				c.wait(lock, [&]()->bool {return !flag; });
				cout << j << endl;
				j += 2;
				flag = true;
				c.notify_one();
			}
		});
	t1.join();
	t2.join();
}

int main()
{
	two_thread_print();
}